package com.supinfo.youFood.obj;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.supinfo.food.entities.Customer;

public class VarGlobal {

		private static VarGlobal instance;
		private Map<String, Object> varList;
		
	    public static VarGlobal getInstance() {
	        if (null == instance) {
	            instance = new VarGlobal();
	        }
	        return instance;
	    }

	    private VarGlobal() {
	    	varList = new HashMap<String, Object>();
	    }

	    
		public Map<String, Object> getVarList() {
			return varList;
		}

		public void setVarList(Map<String, Object> varList) {
			this.varList = varList;
		}

		public static void setInstance(VarGlobal instance) {
			VarGlobal.instance = instance;
		} 
		
		 public Double getTotalPrice() {
		    	Customer currentCustomer = (Customer) varList.get("current");
		    	List<Customer> finalList = (List<Customer>) varList.get("payList");
		    	Double value = 0.0;
		    	if (finalList != null) {
			    	for (Customer customer : finalList) {
			    		if (customer.getId().equals(currentCustomer.getId())) {
			    			for (Candy candy : customer.getCandy())
			    				value += candy.getPrice() * candy.getQuantity();
			    		}
			    	}
		    	}
		    	return value;
		    }
}
